package com.mjw.tender.service;

import com.mjw.tender.api.CommentService;
import com.mjw.tender.domain.Comment;
import com.mjw.tender.domain.CommentB;
import com.mjw.tender.dto.CommentDto;
import com.mjw.tender.dto.SecondCommonDto;
import com.mjw.tender.mapper.CommentBMapper;
import com.mjw.tender.mapper.CommentMapper;
import org.apache.dubbo.config.annotation.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service(version = "1.0.0")
public class CommentServiceImpl implements CommentService {

    @Resource
    CommentMapper commentMapper;
    @Resource
    CommentBMapper commentBMapper;

    @Override
    public int addComment(Comment comment) {
        return commentMapper.insertSelective(comment);
    }

    @Override
    public int addCommentB(CommentB commentB) {
        return commentBMapper.insertSelective(commentB);
    }

    @Override
    public List<Comment> getCommentByArticleId(Long articleId) {
        Example example = new Example(Comment.class);
        example.createCriteria().andEqualTo("articleId",articleId);
        List list = new ArrayList<Comment>(commentMapper.selectByExample(example));
        return list;
    }

    @Override
    public List<CommentB> getCommentBByArticleId(Long articleId) {
        Example example = new Example(CommentB.class);
        example.createCriteria().andEqualTo("articleId",articleId);
        List list = new ArrayList<CommentB>(commentBMapper.selectByExample(example));
        return list;
    }

    @Override
    public List<CommentDto> getCommentDto(Long articleId,Long userId) {
        return commentMapper.selectCommenDtoByAid(articleId,userId);
    }

    @Override
    public List<SecondCommonDto> SecondCommonDto(Long articleId) {
        return commentBMapper.selectSecondCommonDtoByAid(articleId);
    }

    @Override
    public List<CommentDto> getRecentComment(Integer num) {
        return commentMapper.selectOrderByTs(num);
    }
}
